
#include <project_config.h>
#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <any>
#include <vector>


using namespace std;
string fileContent;
string version = "0.1.0";
// AST对象树，用于存储语法树
map<string, any> astTree;
vector<string> split_code = {};


int main(int argc, char* argv[]) {
    // 读取第一个参数
    if (argc < 2) {
        cout << "Error: no file path provided." << endl;
        return 0;
    }
    string value_1 = argv[1];
    if (value_1 == "--help") {
        cout << "Usage: heil [file_path]" << endl;
        return 0;
    }
    else if (value_1 == "--version") {
        cout << "Version: " << version << endl;
        return 0;
    }
    // 读取文件内容
    ifstream file(value_1);
    if (file.is_open()) {
        string line;
        while (getline(file, line)) {
            fileContent += line + "\n";
        }
        file.close();
    }
    else {
        cout << "Error: file not found." << endl;
        return 0;
    }

    try {
        JsRuntime JsRuntime("init_main",split_code_into_tokens(fileContent));
        JsRuntime.path = argv[1];
        JsRuntime.build();
        JsRuntime.run();
    }catch(const exception& e) {
        cout << "Error: " << e.what() << endl;
    }

    return 0;
}

